<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="calculate"/>
    <button id="btn">计算</button>
</body>
<script>
    var btn=document.getEelmentById("btn");
    var calculate=document.getEelmentById("calculate");
    //当点击按钮时 将文本框中运算式运算结果alert出来
    btn.onclick=function(){
        var a=calculate.value;
        var result=eval(a);
        alert("eval(calculate.value)="+result);
        /* var result=eval(calculate.value);
        alert(calculate.value+"="+result); */
    }
</script>
</html>